package com.gwz.sys.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gwz.sys.service.NoticeService;
import com.gwz.sys.utils.DataGridView;
import com.gwz.sys.utils.ResultObj;
import com.gwz.sys.utils.WebUtils;
import com.gwz.sys.vo.NoticeVo;

@RestController
@RequestMapping("notice")
public class NoticeController {
	
	@Autowired
	private NoticeService noticeService;
	
	@RequestMapping("loadAllNotice")
	public DataGridView loadAllNotice(NoticeVo noticeVo) {
		return noticeService.queryAllNotice(noticeVo);
	}
	
	@RequestMapping("deleteNotice")
	public ResultObj deleteNotice(NoticeVo noticeVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			noticeService.deleteNotice(noticeVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("addNotice")
	public ResultObj addNotice(NoticeVo noticeVo) {
		ResultObj resultObj = new ResultObj(200, "添加成功");
		try {
			noticeVo.setCreatetime(new Date());
			noticeVo.setOpername(WebUtils.getCurrentUser().getName());
			noticeService.addNotice(noticeVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("添加失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("updateNotice")
	public ResultObj updateNotice(NoticeVo noticeVo) {
		ResultObj resultObj = new ResultObj(200, "修改成功");
		try {
			noticeService.updateNotice(noticeVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("修改失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("batchDelete")
	public ResultObj batchDelete(NoticeVo noticeVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			noticeService.batchDelete(noticeVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
}
